package com.onlyphoto.onlymall.mvp.model

import com.google.gson.Gson
import com.onlyphoto.onlymall.api.Urls
import com.onlyphoto.onlymall.base.BaseModel
import com.onlyphoto.onlymall.base.BaseObserver
import com.onlyphoto.onlymall.bean.GoodsSimpleBean
import com.onlyphoto.onlymall.bean.request.PayBean
import com.onlyphoto.onlymall.bean.response.AddressBean
import com.onlyphoto.onlymall.bean.response.CouponBean
import com.onlyphoto.onlymall.bean.response.FreightBean
import com.onlyphoto.onlymall.bean.response.OrderSuccessBean
import com.onlyphoto.onlymall.utils.ConfigUtil
import com.onlyphoto.onlymall.utils.RxTransformer


class MOrderConfirmImpl : BaseModel(){
    var url = ""
    fun requestUserAddress(baseObserver: BaseObserver<ArrayList<AddressBean>>) {
        url = ConfigUtil.instance.getUrl(Urls.USER_ADDRESS)
        apiService().userAddress(url)
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }

    fun requestFreight(dataJson: ArrayList<GoodsSimpleBean>, baseObserver: BaseObserver<FreightBean>) {
        url = ConfigUtil.instance.getUrl(Urls.FREIGHT_FIGURE)
        apiService().getFreight(url, Gson().toJson(dataJson))
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }

    fun getUserCoupons(baseObserver: BaseObserver<ArrayList<CouponBean>>, get_type: Int, status: Int){
        url = ConfigUtil.instance.getUrl(Urls.COUPON)
        apiService().getUserCoupons(url, get_type, status)
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }

    fun pay(baseObserver: BaseObserver<OrderSuccessBean>, bean: PayBean){
        url = ConfigUtil.instance.getUrl(Urls.GOODS_ORDER)
        apiService().pay(url, bean.toMap())
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }
}
